package com.kuang.config;

import com.kuang.interceptor.LoginHandlerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig  implements WebMvcConfigurer {


    /**
     * 登录拦截
     * @param registry
     */
//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        String[] addPathPatterns = {
//                "/**",
//        };
//
//        String[] excludePathPatterns = {
//                "/user/login",
//                "/login",
//                "/css/**",
//                "/js/**",
//                "/fonts/**",
//                "/images/**"
//        };
//        registry.addInterceptor(new LoginHandlerInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
//
//    }


    /**
     * 首页通过配置的形式展示
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/index", "/");
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/all-product").setViewName("all-product");
        registry.addViewController("/orders").setViewName("orders");
        registry.addViewController("/calendar").setViewName("calendar");
        registry.addViewController("/register").setViewName("register");
    }

    /**
     * 注册 国际化处理
     * @return
     */
    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResoler();
    }

}
